package com.work.dyduser.base;


import android.content.Intent;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentTransaction;
import android.view.View;
import android.widget.Button;
import android.widget.FrameLayout;
import android.widget.RadioButton;
import android.widget.TextView;

import com.work.dyduser.R;
import com.work.dyduser.utils.UIUtils;


/**
 * 通用Activity,自带标题栏,用于包裹Fragment
 *
 * @author Created by WZ on 2015年1月26日
 */
public class CommonActivity extends BaseActivity {
    /**
     * 标题栏
     */
    protected TitleBar mTitleBar;
    protected FrameLayout mContainer;
    private Fragment mFragment;
    private String title;


    @Override
    protected int getLayoutId() {
        return R.layout.activity_common;

    }

    @Override
    protected void initView() {
        mContainer = (FrameLayout) findViewById(R.id.fl_common_container);
    }

    @Override
    protected void initData() {
        Class<Fragment> clazz = (Class<Fragment>) getIntent().getExtras().get(
                "fragment");
        FragmentTransaction ft = getSupportFragmentManager().beginTransaction();
        mFragment = Fragment.instantiate(getApplicationContext(),
                clazz.getName());
        ft.add(R.id.fl_common_container, mFragment);
        // ft.addToBackStack("back");
        ft.commit();
        setMidleTitle();
    }

    //设置标题
    private void setMidleTitle() {
        title = getIntent().getStringExtra("title");
        mTitleBar.titleMiddle.setText(title);
    }

    public TitleBar getTitleBar() {
        return mTitleBar;
    }


    @Override
    protected void onActivityResult(int requestCode, int resultCode, Intent data) {
        super.onActivityResult(requestCode, resultCode, data);
        mFragment.onActivityResult(requestCode, resultCode, data);
    }

    @Override
    protected void processClick(View v) {
        // TODO Auto-generated method stub
        super.processClick(v);
        switch (v.getId()) {
            case R.id.btn_back:
                finish();
                break;
            case R.id.title_right:
                //消息
                UIUtils.showToast("消息");
                break;
        }
    }

    @Override
    protected void onStop() {
        // TODO Auto-generated method stub
        super.onStop();

    }
}
